# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.test import TestCase

# Create your tests here.
from deviceManager.models import deviceManager,deviceInfo,taskTable
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from itertools import chain



def getNextTask():
    return getAllTask()[0]

def getAllTask():
    return taskTable.objects.filter(task_isDel=False, task_isDone=False).order_by("act_time")

def getDeviceInfoById(_info_id):
    return deviceInfo.objects.filter(is_delete='False', info_id= _info_id)

def getAllDevice():
    return deviceManager.objects.filter(is_delete='False')

def getDeviceById(_device_id):
    return deviceManager.objects.filter(is_delete='False', device_id= _device_id)

def createOneTask(_task_to_device, _wind_act, _water_act, _light_act, _device_status, _act_time):
    task = taskTable(_task_to_device, _wind_act, _water_act, _light_act, _device_status, _act_time)
    task.save()
    # device = deviceManager.objects.filter(device_id='298309')
    # print taskTable.objects.filter(task_isDel=False, task_isDone=False).order_by("act_time").values('task_to_device_id', 'deviceManager__device_name')
    # print taskTable.objects.filter(task_isDel=False, task_isDone=False).order_by("act_time").values('task_id', 'task_to_device')